import { WSController, OnWSMessage, OnWSConnection, Inject, App, WSEmit } from '@midwayjs/core';
import { Context, Application } from '@midwayjs/socketio';

@WSController('/')
export class HelloSocketController {

    @Inject()
    ctx: Context;

    @App()
    app: Application;

    @OnWSConnection()
    async onConnectionMethod() {
        console.log('有人连接进来了', this.ctx.id);
    }


    @OnWSMessage('myEvent')
    async gotMessage(data) {
      console.log('on data got', this.ctx.id, data);
    }


   
    @OnWSMessage('myEvent2')
    @WSEmit('myEventResult')
    async gotMessage3(data) {
      // TODO
    //   this.ctx.emit("hello", "can you hear me?", 1, 2, "abc");
      this.ctx.broadcast.emit("broadcast", data);
    console.log(data);
    
      return { 
         code:2000
      }
    } 

}